"""系统设置页面"""
from page.base_page import BasePage
from selenium.webdriver.common.by import By
from config.config import PROJECT_PATH
from os.path import join
from time import sleep
class SysSettingPage(BasePage):
    # 网页定位器
    xy_locator = (By.TAG_NAME, 'html')
    # 保存按钮
    btn_save_locator=(By.NAME, "submit")
    # 后缀输入框定位器
    suffix_locator = (By.NAME, 'allow_file_type')
    # 系统log
    logo_locator = (By.NAME, 'logo')
    # SMTP定位器
    SMTP_locator = (By.LINK_TEXT, 'SMTP设置')
    # 合同提醒时间定位器
    contract_alert_time_locator = (By.NAME, 'contract_alert_time')
    #数据无变化定位器
    not_data_locator=(By.CSS_SELECTOR,'body > div.container > div.alert.alert-error')
    #设置成功并保存定位器
    setting_success_locator=(By.CSS_SELECTOR, 'body > div.container > div.alert.alert-success')


    url='/crm5/index.php?m=setting&a=defaultInfo'
    def click_save(self):
        """点击保存按钮"""
        # 滑动页面到最下面
        xy = self.driver.find_element(*self.xy_locator).size
        js = 'window.scroll(0, %s)' % (xy['height'])
        self.driver.execute_script(js)
        # 点击保存
        self.driver.find_element(*self.btn_save_locator).click()
    def input_suffix(self,suffix="pdf,doc,jpg,png,gif,txt,doc,xls,zip,docx"):
        """输入后缀名"""
        self.driver.find_element(*self.suffix_locator).clear()
        self.driver.find_element(*self.suffix_locator).send_keys(suffix)
    def upload_logo(self,logo_path=join(PROJECT_PATH,'data','QQ图片20220428123008.jpg')):
        """上传图片"""
        self.driver.find_element(*self.logo_locator).send_keys(logo_path)
    def input_contract(self,time=1):
        """输入合同提醒时间"""
        self.driver.find_element(*self.contract_alert_time_locator).clear()
        self.driver.find_element(*self.contract_alert_time_locator).send_keys(time)
    def click_smtp(self):
        """点击smtp"""
        self.driver.find_element(*self.SMTP_locator).click()
    def get_not_data_texe(self):
        """获取数据无变化的文本内容"""
        return self.driver.find_element(*self.not_data_locator).text
    def get_setting_success_texe(self):
        """获取设置成功的文本内容"""
        return self.driver.find_element(*self.setting_success_locator).text
